<?php
// View for admin - leagues
require_once WACT_ROOT.'controller/controller.inc.php';
require_once WACT_ROOT .'controller/form.inc.php';
require_once WACT_ROOT.'view/view.inc.php';
require_once WACT_ROOT .'view/formview.inc.php';

require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';

require_once 'model/common/user.php';
require_once 'model/common/league.php';
require_once 'model/common/categories.php';
require_once 'model/common/date.php';
require_once 'model/common/session.php';


class LeaguesListView extends LayoutFormView {

    function LeaguesListView($TemplateFile) {
        parent :: LayoutFormView($TemplateFile);
    }

    function prepare(&$controller, &$request, &$responseModel) {
    	parent::prepare($controller, $request, $responseModel);
        		        
		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
 

		$pager =& $this->Template->getChild('pagenav');
        $pager2 =& $this->Template->getChild('pagenav2');
        $list =& League::getLeaguesList($pager, $request, $responseModel);
        $list->paginate($pager2);


        $list_updated=array();


        $list->reset();
        while ($list->next()) {

        	$dataspace = $list->export();
            $firstname = $list->get('firstname');
            $lastname = $list->get('lastname');
            $event = $list->get('event');

            $event_show = League::getEventName($event);
            $dataspace['event_show'] =  $event_show;

            $league_id = $list->get('league_id');
            $author_show = $firstname.' '.$lastname;
            $dataspace['author_show'] =  $author_show;

            $category1 = $list->get('category1');
            $category2 = $list->get('category2');

            if ($category1 && $category2) $category_show = $category1.'-'.$category2;
            else if ($category1) $category_show = $category1;
            else if ($category2) $category_show = $category2;

            $dataspace['category_show'] =  $category_show;

            $premium = $list->get('premium');
            if ($premium) $dataspace['premium_show'] =  1;

            $list_updated[$league_id] = $dataspace;
        }


        $list_source_updated =& new ArrayDataSet($list_updated);
        //print_r($list_source_updated);
        $this->Template->setChildDataSource('List', $list_source_updated);

        //populate sort combo
        $sortby =& $this->Template->getChild('sort');
        $sort_list = array('league_id'=>'ID','event'=>'Event', 'name'=>'Name',
        'category_id, category2_id'=>'Category');
        $sortby->setChoices($sort_list);

        //populate categories
        $categories1 =& CategoriesModel::getSportCategories(false,false);
        //print_r($categories1);
        $categories2 =& CategoriesModel::getCommunityCategories(false,false);
        $category1 =& $this->Template->getChild('category1');
        $category2 =& $this->Template->getChild('category2');
        $category1->setChoices($categories1);
        $category2->setChoices($categories2);

        //populate events
        $events =& League::getEventsList();
        $event_element =& $this->Template->getChild('event_id');
        $event_element->setChoices($events);



    }

}






?>